
  /*
	@Author: 于辉
	@Time: 2020-11
	@Tittle: selectUsers
	@Description: 选中用户列表
*/
layui.use(['layer','jquery',"table"],function(){
	var layer= layui.layer
	    table = layui.table;

	var maxSelectNum = getUrlParam("maxNum");
	var index = parent.layer.getFrameIndex(window.name);
    console.log(maxSelectNum<=1)
    //渲染数据列表
    var renderTable = function (param){
        table.render({
            id: 'userID'
            ,elem: '#dataTable'
            ,even: true //开启隔行背景
            ,url:getServerPath("GETUSETLIST")
            ,method: 'post'
            ,contentType: 'application/json'
            ,height: 'full-150'
            ,headers:{SYSTOKEN: getSettings("token")}
            ,where: {
                "queryText": $("#search_input").val(),
                "orderBy": "createTime",
                "sort": "descending"
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res)
                return {
                    "code": res.statusCode == 200?0:res.statusCode, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.totalCount, //解析数据长度
                    "data": res.data.dataSource //解析数据列表
                };
            }
            ,cols: [[
                {type:'radio' ,hide:maxSelectNum >1}
                ,{type:'checkbox',hide:maxSelectNum<=1}
                ,{field:'userID', width:80, title: 'ID',hide:true, sort: true}
                ,{field:'nickName',  title: '姓名',align:"center"}
                ,{field:'phone', width:150, title: '手机号',align:"center"}
                ,{field:'sex', width:80, title: '性别',align:"center"}
                ,{field:'enabled', width:150, title: '是否启用',align:"center",templet:function(row){
					if(row.enabled){
						return "启用";
					}else{
						return "禁用";
					}
				}}
            ]]
            ,page: {
            	limit:8,
                layout:['count', 'prev', 'page', 'next','count','skip']
			}
        });
        $('#page').css('text-align', 'right');  // 分页右对齐
        $('.layui-table-page').css('text-align', 'right');  // 数据表格分页右对齐
    }

    renderTable();

    $("#search_input").on("change",function(){
        renderTable();
    })
	//取消
	$("#btn_cancle").click(function(){
		parent.layer.close(index)
	})

	//确认
	$("#btn_save").click(function(){
		var checkStatus = table.checkStatus('userID'); 
	 	if(checkStatus.data.length<=0){
	 		layer.alert("请至少选中一条数据进行操作!",{icon:5});
	 		return;
	 	}
	 	var selectIds = new Array();
        var selectName = new Array();
	 	for(var i=0;i<checkStatus.data.length;i++){
	 		selectIds.push(checkStatus.data[i].userID);
            selectName.push(checkStatus.data[i].nickName);
	 	}
		parent.selectUserCallback(selectIds,selectName);
        parent.layer.close(index)
	})
});